package com.gitee.wsl.common.ui.ext

import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.DpOffset
import androidx.compose.ui.unit.lerp
import kotlin.math.ln

@Composable
 fun Dp.toPx(density: Density= LocalDensity.current) = with(density) { this@toPx.toPx() }

@Composable
 fun Int.toDp() = with(LocalDensity.current) { this@toDp.toDp() }

@Composable
 fun Float.toDp() = with(LocalDensity.current) { this@toDp.toDp() }

/**
 * The [Double] as [Dp].
 */
@Composable
fun Double.toDp(): Dp = toFloat().toDp()

fun lerpDpOffset(start: DpOffset, end: DpOffset, progress: Float): DpOffset =
    DpOffset(lerp(start.x, end.x, progress), lerp(start.y, end.y, progress))

internal fun Dp.alphaLN(
    constant: Float = 1f,
    weight: Float = 0f,
): Float = ((constant * ln(value + 1) + weight) + 2f) / 100f